<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 17:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

    <title>学生信息</title>

    <script type="text/javascript">
        function validate() {
            var id = document.forms[0].id.value;
            var name = document.forms[0].name.value;
            var title = document.forms[0].title.value;
            var comment = document.forms[0].comment.value;

            if (id <= 0) {
                alert("ID号不能为空，请输入ID号！");
                return false;
            } else if (name.length <= 0) {
                alert("类型不能为空！");
                return false;
            } else if (title.length <= 0) {
                alert("标题不能为空！");
                return false;
            } else if (comment.length <= 0) {
                alert("内容不能为空！");
                return false;
            } else {
                return true;
            }
            //document.getElementById("form").submit();
        }
    </script>
</head>
<link rel="stylesheet" href="css/header.css">


<body background="resourse/bg.jpg">
<%//判断是否登录
    String userid=(String)session.getAttribute("userid");
//    System.out.print("Session userID="+userid);
    if (userid!=null) {
%>

<!--页头-->
<div id="header">
    <spana>&emsp;巴以小记</spana>
    <br>
    <spanb>&emsp;&emsp;<%=(String)session.getAttribute("userid")%> 在线中..</spanb>
    <ul>
        <li></li>
        <li><h2 class="main" ><a class="btna" href="main.jsp">主页</a></h2></li>
        <li><h2 class="work"><a class="btna" href="addInfo.jsp">发贴</a></h2></li>
        <li><h2 class="new"><a class="btna" href="showInfo.jsp" >看贴</a></h2></li>
        <li><h2 class="comment"><a class="btna" href="showInfo.jsp" >搜索</a></h2></li>
    </ul>
</div>
<br>

    <%
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");

        String id = request.getParameter("id");
        Connection conn = null;
        Statement stat = null;
        ResultSet rs = null;
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/talknewsdatabase";
        String user = "root";
        String password = "123456";
        conn = DriverManager.getConnection(url, user, password);
        stat = conn.createStatement();

        rs = stat.executeQuery("select * from info where user_id='" +userid +  "' and id=" + id + "");

    %>


    <center>
         <%while (rs.next()) { %>
            <br>
            <form action="doupdate.jsp" method="post" onSubmit="return validate()">
                <table cellSpacing=2 >
                    <tr>
                         <th colspan="2" align="center"><h3 align="center">标题：<input type="text" name="title" value="<%=rs.getString("title") %>"  title="标题不能为空"  style="height:30px; width:850px; font-size:30px;"/></h3></th>
                    </tr>
                    <tr>
                        <td align="center">编号：<input type="text" name="id" value="<%=rs.getString("id") %>" title="ID号不可改" readonly="readonly"></input></td>
                        <td align="center">类型：<input type="text" name="name" value="<%=rs.getString("name") %>" title="类型不能为空"></input></td>
                    </tr>
                    <tr>
                        <td align="center"  colspan="2"> <textarea name="comment" rows="20" cols="90" style="font-size:20px" title="内容不能为空"><%=rs.getString("comment")%></textarea></td>
                    </tr>
                    <tr><td align="center"  colspan="2"><input type="submit" value="修改"/></td></tr>
                </table>
            </form>

            <h3><a href=showInfo.jsp>返回信息查询页面</a></h3>

        <%}%>
    </center>



    <%
        if (rs != null) {
            rs.close();
            rs = null;
        }
        if (stat != null) {
            stat.close();
            stat = null;
        }
        if (conn != null) {
            conn.close();
            conn = null;
        }
    %>

<%
    } else {
        out.print("<script>alert('未成功登录！');" +
                "window.location='http://localhost:8080/index.html';</script>");
    }
%>

</body>
</html>